using System;

namespace OpenWaves
{
    public class FileUrlBuilder:UrlBuilder
    {
        protected override Url BuildUrl()
        {
            var uriBuilder = new UriBuilder
                                 {
                                     Scheme = Uri.UriSchemeFile,
                                     Path = this.Path.ToString(),
                                     Query = UrlQueryCollection.FromNameValueDictionary(this.Query).ToString(),
                                     Fragment = this.Fragment,
                                     Host=null
                                 };

            return new FileUrl(uriBuilder.Uri);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public static UrlBuilder From(FileUrl url)
        {
            var builder = new FileUrlBuilder
                              {
                                  Fragment = url.Fragment,
                                  Path = url.Path,
                              };

            foreach (var parameter in url.Query)
            {
                builder.AddParameter(parameter.Key, parameter.Value);
            }

            return builder;
        

        }
    }
}